package com.tt.dp.iterator;

import com.tt.dp.iterator.model.MenuItem;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class PancakeHouseMenu implements Menu<MenuItem>{

    private List<MenuItem> items;

    public PancakeHouseMenu() {

        items = new ArrayList<MenuItem>();

        addItem("K&B's Pancake Breakfast","Pancakes with scrambled eggs, and toast",true,2.99);
    }

    public void addItem(String name, String description, boolean vegetarian, double price) {
        MenuItem menuItem = new MenuItem(name, description, vegetarian, price);

        items.add(menuItem);
    }

    public Iterator<MenuItem> createIterator(){
        return new PancakeHouseMenuIterator(this.items);
    }

    public List<MenuItem> getItems() {
        return items;
    }

    private class PancakeHouseMenuIterator implements Iterator<MenuItem>{

        private int position = 0;

        private List<MenuItem> items;

        public PancakeHouseMenuIterator(List<MenuItem> items){
            this.items = items;
        }

        public boolean hasNext() {
            return items.size() > 0 && position <= items.size() - 1;
        }

        public MenuItem next() {

            MenuItem item = items.get(position);

            position += 1;
            return item;
        }

        public void remove() {

        }
    }
}
